package Ajax;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/registerAjax.do")
public class RegisterServletAjax extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException
    {
        String username=req.getParameter("username");
        String password=req.getParameter("password");
        JSONObject json=new JSONObject();

        if (password.length()>8){
            json.put("status","success");
        }else {
            json.put("status","error");
        }
        resp.setContentType("application/json;charset=utf-8");   //格式
        resp.getWriter().write(JSON.toJSONString(json));
        }

    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException
    {
        String username=req.getParameter("username");
        String password=req.getParameter("password");
        JSONObject json=new JSONObject();

        if (password.length()>8){
            json.put("status","success");
        }else {
            json.put("status","error");
        }
        resp.setContentType("application/json;charset=utf-8");   //格式
        resp.getWriter().write(JSON.toJSONString(json));
    }

}

